using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class InputBox : UserControl
	{
		public delegate void dismissWithClickBtn(object sender, int nClickIndex);
		private ModeDialogHelper mDlgHelper;
		internal Grid LayoutRoot;
		internal TextBlock txtTitle;
		internal Image imgContent;
		internal TextBlock txtContent;
		internal PhoneTextBox txtInput;
		internal Button btnLeft;
		internal Button btnRight;
		private bool _contentLoaded;
		public event InputBox.dismissWithClickBtn mBtnClick;
		public InputBox(bool isEnableBackKeyPress, string strTitle, string strContent, string strLeftBtnTitle, string strRightBtnTitle, string strInputBoxHint, InputBox.dismissWithClickBtn clickHandler = null, BitmapImage image = null)
		{
			this.InitializeComponent();
			this.LayoutRoot.set_Background(R.theme.COMMON_APPBAR_BK_BRUSH);
			this.txtTitle.set_Text(strTitle);
			this.txtContent.set_Text(strContent);
			this.btnLeft.set_Content(strLeftBtnTitle);
			this.btnRight.set_Content(strRightBtnTitle);
			this.txtInput.Hint = strInputBoxHint;
			if (image != null)
			{
				this.imgContent.set_Source(image);
			}
			else
			{
				this.imgContent.set_Visibility(1);
				this.txtContent.set_Width(440.0);
			}
			this.mBtnClick = clickHandler;
			this.mDlgHelper = new ModeDialogHelper(this, isEnableBackKeyPress, (SolidColorBrush)Application.get_Current().get_Resources().get_Item("NearOpacityBrush1"), false);
		}
		private void txtInput_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (string.IsNullOrEmpty(this.txtInput.get_Text()))
			{
				this.btnLeft.Focus();
				this.txtInput.Focus();
			}
		}
		public static InputBox Show(string strTitle, string strContent, string strLeftBtnTitle, string strRightBtnTitle, string strInputBoxHint, InputBox.dismissWithClickBtn clickHandler = null, BitmapImage imgContent = null)
		{
			InputBox inputBox = new InputBox(true, strTitle, strContent, strLeftBtnTitle, strRightBtnTitle, strInputBoxHint, clickHandler, imgContent);
			inputBox.mDlgHelper.Show();
			return inputBox;
		}
		private void btnLeft_Click(object sender, RoutedEventArgs e)
		{
			if (string.IsNullOrEmpty(this.txtInput.get_Text()))
			{
				this.txtInput.set_Text("");
			}
			if (this.mBtnClick != null)
			{
				this.mBtnClick(this, 0);
			}
			this.mDlgHelper.Hide(null);
		}
		private void btnRight_Click(object sender, RoutedEventArgs e)
		{
			if (this.mBtnClick != null)
			{
				this.mBtnClick(this, 1);
			}
			this.mDlgHelper.Hide(null);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Util/InputBox.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.imgContent = (Image)base.FindName("imgContent");
			this.txtContent = (TextBlock)base.FindName("txtContent");
			this.txtInput = (PhoneTextBox)base.FindName("txtInput");
			this.btnLeft = (Button)base.FindName("btnLeft");
			this.btnRight = (Button)base.FindName("btnRight");
		}
	}
}
